<%@ page import="com.hrm.entity.EmployeeEntity" %><%--
  Created by IntelliJ IDEA.
  User: zekdot
  Date: 20-3-16
  Time: 下午8:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <link href="${pageContext.request.contextPath}/css/main.css" rel="stylesheet" type="text/css" />
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
</head>
<%
    EmployeeEntity employeeEntity = (EmployeeEntity) session.getAttribute("user");
%>
<div class="pub_box" style="height: 50%">
    <div class="div_float1">
            <p class="form_p"><label class="form_label">员工编号：</label><input type="text" class="form_input1 " minlength="2"  required id="EId" > </p>
            <p class="form_p"><label class="form_label">职位：</label><select class="form_input1" id="pos">
            </select>
            </p>
            <p class="but_p"><input type="button" value="保存" id="sub" class="but_save"/></p>

    </div>

</div>
<script>
    $.get('${pageContext.request.contextPath}/department/pos?dep=<%=employeeEntity.getDepartment()%>',{},function(str){
        var res = eval('(' + str + ')');
        var poss = res.object;
        for(var i=0;i<poss.length;i++){
            $('#pos').append('<option value="' + poss[i] + '">' + poss[i] + '</option>')
        }
    });
    $(function(){
        var index = parent.layer.getFrameIndex(window.name); //获取当前窗体索引
        $('#close').on('click', function(){
            parent.layer.close(index); //执行关闭

        });

    })
</script>
<script>
    function isEId(str){
        if(str.length != 11)
            return false;
        if(str[0] != 'E'){
            return false;
        }
        for(var i=1;i<4;i++){
            if(str[i] <'a' || str[i] > 'z')
                return false;
        }
        for(var i=4;i<11;i++){
            if(str[i] < '0' || str[i] > '9')
                return false;
        }
        return true;
    }
    $('#sub').click(function(){
        var id = $('#EId').val(),pos = $('#pos').val();
    // alert(id)
        if(!isEId(id)){
            alert('输入了非法的员工编号');
            return ;
        }
        var data = {'id':id,'pos':pos};
        $.post('${pageContext.request.contextPath}/employee/add',data,function(str){
            var res = eval('(' + str + ')');
            if(res.code != 0){
                alert(res.message);
            }else{
                alert('添加成功！');
                $('#EId').val('');
            }
        });
    });
</script>
</html>